#!/bin/bash

# shellcheck source=meta-facebook/recipes-fb/obmc_functions/files/fb-common-functions
source /usr/libexec/fb-common-functions
# shellcheck source=meta-facebook/meta-harma/recipes-phosphor/state/phosphor-state-manager/power-cmd
source /usr/libexec/phosphor-state-manager/power-cmd

check_valid_sgpio
valid_sgpio=$?

# Set Host Power Status Running
if [ "$valid_sgpio" -eq 0 ]; then
    busctl set-property xyz.openbmc_project.State.Host0 \
    /xyz/openbmc_project/state/host0 \
    xyz.openbmc_project.State.Host \
    CurrentHostState s \
    xyz.openbmc_project.State.Host.HostState.Running

    systemctl start obmc-led-group-start@power_on.service
fi

# The hardware disables the multiplexer in standby
# to prevent sending a command by mistake to the retimer when it boots up.
# Therefore, we need to rebind it when powered on.

if [ ! -e "/sys/bus/i2c/drivers/pca954x/3-0070" ]; then
  sleep 6
  /usr/bin/echo 3-0070 > /sys/bus/i2c/drivers/pca954x/bind
fi

exit 0
